package com.qfedu.yuxiaoer.controller;

import com.qfedu.yuxiaoer.common.api.CommonResult;
import com.qfedu.yuxiaoer.entity.HouseLease;
import com.qfedu.yuxiaoer.service.HouseLeaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author Dc
 * @Date 2023/2/15 21:05
 */
@RestController
@RequestMapping("/house")
@Api(tags = "houseController", description = "整租/合租管理")
public class HouseLeaseController {

    @Autowired
    private HouseLeaseService houseLeaseService;

    @ApiOperation(value = "新增整租/合租信息")
    @RequestMapping(value = "/addLease", method = RequestMethod.POST)
    public CommonResult addLease(@RequestBody HouseLease houseLease) {
        if (houseLease != null) {
            return houseLeaseService.addHouseLease(houseLease);
        } else {
            return CommonResult.failed("新增整租/合租失败");
        }
    }

    @ApiOperation(value = "根据ID查询整租/合租信息")
    @RequestMapping(value ="findById", method = RequestMethod.GET)
    public CommonResult findById(Integer id) {
        return houseLeaseService.findHouseLeaseById(id);
    }

    @ApiOperation(value = "根据小区名字查询整租/合租信息,如不填则为查询所有")
    @RequestMapping(value = "findByCommunity", method = RequestMethod.GET)
    public CommonResult<List<HouseLease>> findByCommunity(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit, String community) {
        return houseLeaseService.findHouseLeaseByCommunity(page, limit, community);
    }

    @ApiOperation(value = "根据ID删除整租/合租信息")
    @RequestMapping(value = "deleteById", method = RequestMethod.DELETE)
    public CommonResult deleteById(Integer id) {
        return houseLeaseService.deleteById(id);
    }
}
